package com.example.api.controller.app;


import com.example.api.dto.AddressDTO;
import com.example.api.query.AddressQuery;
import com.example.api.query.BookQuery;
import com.example.api.service.AddressService;
import com.example.api.service.BookService;
import com.example.api.utils.PageResult;
import com.example.api.utils.Result;
import com.example.api.utils.ThreadContextUtil;
import com.example.api.vo.AddressVO;
import com.example.api.vo.BookVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "订单接口")
@RestController("appBookController")
@RequestMapping("/app/book")
public class BookController {

    @Resource
    BookService bookService;

    @GetMapping
    @ApiOperation("订单搜索")
    public Result<List<BookVO>> list(BookQuery bookQuery) {
        //获取当前的顾客的id
        Long customerId = ThreadContextUtil.getData();
        bookQuery.setCustomerId(customerId);

        PageResult<BookVO> page = bookService.findApp(bookQuery);
        return Result.ok("成功",page.getList(),page.getTotal());
    }


    @ApiOperation("下单")
    @PostMapping
    public Result add(long addressId,String remark){

        Map<String,Object> result = bookService.add(addressId,remark);


        return Result.ok("下单成功", result);
    }

}
